 
 import api from '@/api/api.js'
 const appUpdate = ()=> {
	  return console.log('更新')
	    api.getApkVersion().then(res => {
	      // 假设 res 结构如下
	      // {
	      //   apkVersionCode: 100,  // 版本号
	      //   apkUrl: "https://xxx.com/app.apk",
	      //   ishot: false,   // 是否热更新
	      //   wgtUrl: "https://xxx.com/app.wgt"
	      // }
	      // #ifdef APP-PLUS
	      plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
	        const localVersionCode = Number(widgetInfo.versionCode)
			console.log(localVersionCode,'localVersionCode')
			if(!res.apkVersionCode) return
			if(res.apkVersionCode<=localVersionCode) return
	        // 1. 全包更新
	        if (!res.ishot) {
	          uni.showModal({
	            title: '更新提示',
	            content: '发现新版本，是否前往更新？',
	            confirmText: '确定',
	            success: (modalRes) => {
	              if (modalRes.confirm) {
	                // 跳转到浏览器下载 apk
	                plus.runtime.openURL(res.apkUrl)
	              }
	            }
	          })
	        } else  {
	          // 2. wgt 静默更新
	          const downloadWgt = (url) => {
	            const dtask = plus.downloader.createDownload(url, {}, (download, status) => {
	              if (status === 200) {
	                plus.runtime.install(download.filename, { force: true }, () => {
	                  uni.showToast({ title: '更新完成，即将重启' });
	                  setTimeout(() => plus.runtime.restart(), 1000);
	                });
	              } else {
	                uni.showToast({ title: '更新包下载失败', icon: 'none' });
	              }
	            });
	            dtask.start();
	          };
	          downloadWgt(res.wgtUrl)
	        }
	      });
	      // #endif
	    })
}

  
  export default appUpdate